package com.exchange.employee.config;

import com.exchange.employee.entity.Employee;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;

public interface EmployeeRepository extends ElasticsearchRepository<Employee, Long> {

    List<Employee> findByAboutContainsAndAboutContains(String searchStr, String key);

    int countByAboutContainsAndAboutContains(String searchStr, String key);

    @Query("{\"match\" : {\"about\" : {\"query\" : \"?0\", \"minimum_should_match\" : \"?1\" }}}")
    Page<Employee> findByAboutContains(String keys, String minMatch, Pageable pageable);

    @Query("{\"bool\" : {\"should\" : [ " +
            "{\"match\" : {\"about\" : {\"query\" : \"?0\", \"minimum_should_match\" : \"?1\" }}}," +
            "{\"match\" : {\"last_name\" : {\"query\" : \"?2\", \"minimum_should_match\" : \"?3\" }}}" +
            "] }}")
    Page<Employee> findByAboutContainsOrLast_nameContains(
            String aboutKey, String aboutMatch,
            String nameKey, String nameMatch,
            Pageable pageable);

//    List<Employee> Employee

}
